<script>
import pubsub from 'pubsub-js';
export default {
  name: "MySchool",
  data() {
    return {
      name: "武汉大学",
      address: "武汉",
      studentName: ""
    }
  },
  mounted() {
    this.puId = pubsub.subscribe("getStudentName", (getStudentName,data)=>{
      this.studentName = data;
    });
  },
  beforeDestroy() {
    pubsub.unsubscribe(this.puId)
  }
}
</script>

<template>
  <div class="school">
    <h1>收到的学生姓名:{{studentName}}</h1>
    <h2>学校名称:{{ name }}</h2>
    <h2>学校地址:{{ address }}</h2>
  </div>
</template>
<style scoped>
.school {
  background-color: pink;
  padding: 5px;
  margin-top: 30px;
}
</style>